import Vue from 'vue'
export default {
	getImgUrl(icon) {
		return Vue.prototype.$baseUrl + icon;
	},
	//公共方法返回上一页
	allblack() {
		uni.navigateBack({})
	},
	//封装页面跳转
	navigateTo(ai) {
		console.log("dddd")
		uni.navigateTo({
			url: ai
		})
	},

}
//数字过滤器
Vue.filter('formatCount', function(value) {
	if (value >= 10000 && value <= 100000000) {
		value /= 10000;
		return value.toFixed(1) + '万';
	} else if (value > 100000000) {
		value /= 100000000;
		return value.toFixed(1) + '亿';
	} else {
		return value;
	}
});

//检测是否登录
Vue.prototype.checkLogin = () => {
	var userinfo = uni.getStorageSync('userinfo');
	var token = uni.getStorageSync("token");
	console.log(token)
	//var token = uni.getStorageSync("tokens")
	if (token == '') {
		uni.showModal({
			content: '请先注册登录',
			cancelColor: "#808080",
			success: (res) => {
				if (res.confirm) {
					uni.redirectTo({
						url: '../login/login'
					});
				} else {
					console.log("取消登录操作")
				}
			}
		})
		return false;
	}
	return true
}

//获取url
Vue.prototype.$GetRequest = function() {
	//获取url参数
	var url = window.location.href;
	console.log(window.location)
	//创建数组
	var theRequest = new Object();
	//判断?是否存在,以此判断是否有参数
	if (url.indexOf("?") != -1) {
		//拆分成['value=name']
		var str = url.split("?")[1].split("&");
		console.log(str)
		//循环遍历
		str.forEach(item => {
			theRequest[item.split("=")[0]] = decodeURIComponent(item.split("=")[1]);
		});
	}
	console.log(theRequest);
	return theRequest;
}
